package jtk.project4.fleet.task;

import java.util.List;

import jtk.project4.fleet.domain.FuelRec;
import jtk.project4.fleet.domain.FuelTank;
import jtk.project4.fleet.domain.Vendor;
import jtk.project4.fleet.event.GeneralTankInformationEvent;
import jtk.project4.fleet.event.VendorEvent;
import jtk.project4.fleet.event.GeneralTankInformationEvent.GeneralTankInformationEventType;
import jtk.project4.fleet.event.VendorEvent.VendorEventType;
import jtk.project4.fleet.service.DatabaseService;

import nl.coderight.jazz.Task;
import nl.coderight.jazz.event.MessageEvent;
import nl.coderight.jazz.event.ProgressEvent;
import nl.coderight.jazz.event.MessageEvent.MessageEventType;
import nl.coderight.jazz.event.ProgressEvent.ProgressEventType;

public class LoadFuelRecTask extends Task<List<FuelRec>>{
	@Override
	public List<FuelRec> process() throws Exception{
		return DatabaseService.getInstance().getFuelRec();
	}
	
	@Override
	protected void onStart() {
		ProgressEvent progressEvent = new ProgressEvent(ProgressEventType.START);
		progressEvent.setMessage("Loading contacts...");
		progressEvent.setIndeterminate(true);
		postEvent(progressEvent);
	}
	
	@Override
	protected void onFinish() {
		postEvent(new ProgressEvent(ProgressEventType.STOP));
		
		GeneralTankInformationEvent fuelrecEvent = new GeneralTankInformationEvent(GeneralTankInformationEventType.LOAD_SUCCESS);
		fuelrecEvent.setFuelrec(getResult());
		postEvent(fuelrecEvent);
	}
	
	@Override
	protected void onError() {
		MessageEvent error = new MessageEvent(MessageEventType.ERROR);
		error.setMessage(getError().getMessage());
		postEvent(error);			
	}

}
